﻿using System;

namespace DbFrame.DbContext.PostgreSql
{
    using DbFrame.BaseClass;
    using DbFrame.Core.Achieve;
    using DbFrame.Core.CodeAnalysis;
    using DbFrame.DbContext.PostgreSql.Achieve;

    /// <summary>
    /// PostgreSQL 实现
    /// </summary>
    public class DbContextPostgreSQL : BaseDb
    {
        public DbContextPostgreSQL()
        {
            DbSettings.KeywordHandle = (Keyword) => Keyword;
            this.LastInsertId = " RETURNING #ID#; ";
            this.Ado = new PostgreSqlAdoAchieve(this.ConnectionString);
            this.analysis = new Analysis(this.Ado, DbContextType.PostgreSQL);
        }

        public DbContextPostgreSQL(string _ConnectionString) : base(_ConnectionString)
        {
            DbSettings.KeywordHandle = (Keyword) => Keyword;
            this.LastInsertId = " RETURNING #ID#; ";
            this.Ado = new PostgreSqlAdoAchieve(this.ConnectionString);
            this.analysis = new Analysis(this.Ado, DbContextType.PostgreSQL);
        }

        /// <summary>
        /// 注册数据访问对象
        /// </summary>
        /// <param name="_ConnectionString"></param>
        /// <param name="TableInit"></param>
        public static void Register(string _ConnectionString, Action<DbTable> TableInit)
        {
            DbSettings.DefaultConnectionString = _ConnectionString;
            TableInit?.Invoke(new DbTable());
        }



    }
}
